{% extends 'IcsocUIBundle::page.html.twig' %}
{% from 'IcsocUIBundle:Macro:grid.html.twig' import gridWidth,gridNav,gridConfig,gridKeyword,sendKeyWord %}
{% from 'IcsocUIBundle:Macro:actions.html.twig' import playSound %}
{% block stylesheet %}
    {{ parent() }}
    {% stylesheets
    '@jqgird_css'
    '@gritter_css'
    filter='cssrewrite' filter='uglifycss'
    %}
    <link rel="stylesheet" href="{{ asset_url }}" />
    {% endstylesheets %}
{% endblock %}

{% block content %}
    {{ gridKeyword('Phonetic name'|trans, '', types) }}
    {{ playSound() }}
    <table id="grid-table"></table>
    <div id="grid-pager"></div>
{% endblock %}
{% block footer %}
    {% javascripts
    '@jqgird_js'
    '@gritter_js'
    '@common_js'
    filter='uglifyjs'
    %}
    <script src="{{ asset_url }}"></script>
    {% endjavascripts %}
    <script type="text/javascript">
        jQuery(function($) {
            var stype = {};
            {% for key,stype in sound_type %}
                stype["{{ key }}"] = "{{ stype }}";
            {% endfor %}
            {{ gridWidth() }}
            jQuery(grid_selector).jqGrid({
                url: "{{ path('icsoc_sound_list') }}",  //数据；
                mtype: 'POST',
                datatype: "json", //从服务器端返回的数据类型，默认xml：xml，local，json，jsonnp，script，xmlstring，jsonstring，clientside
                height: '100%', //展示高度；
                colNames:['','{{ 'actions'|trans }}','','{{ 'Phonetic name'|trans }}', '{{ 'Voice address'|trans }} ','{{ 'Update time'|trans }}','{{ 'Voice type'|trans }}','{{ 'remark'|trans }}'],  //列显示名称，是一个数组对象
                colModel:[
                    {name:'myac',index:'', width:80, fixed:true, sortable:false, resize:false,
                        formatter:'actions',
                        formatoptions:{
                            keys:true,
                            editbutton:true,
                            editformbutton: true,
                            delOptions:{recreateForm: true, beforeShowForm:beforeDeleteCallback, afterSubmit:afterDeleteCallback},
                            editOptions:{width: "0",height: "0", jqModal:false, beforeShowForm:beforeEditCallback }
                        }
                    },
                    {name:'actions' , index:'actions' , label: '{{ 'actions'|trans }}' , width:50 , sortable:false , fixed:true,formatter:function(value,cell,row){
                        return "<i class='fa fa-youtube-play voice_prover' onclick='listen(\""+row.id+"\")'></i>&nbsp;&nbsp;" +
                                "<i class='fa fa-download' onclick='downSound(\""+row.id+"\")' class='pointer'></i>";
                    }},
                    {name:'id',index:'id', key:true,sortable:false,hidden:true,editable:true },
                    {name:'name',index:'name',editable: true, sortable:false},
                    {name:'address',index:'address', editable:false, sortable:false},
                    {name:'add_time',index:'remark',editable:true, sortable:false },
                    {name:'sound_type',index:'pho_pass', editable:true, sortable:false,formatter:function (cellvalue, options, rowObject) {
                            return stype[cellvalue];
                    }},
                    {name:'remark',index:'remark',editable:true, sortable:false }
                ],
                {{ gridConfig() }}
                loadComplete: function(xhr) {
                    var table = this;
                    setTimeout(function(){
                        updatePagerIcons(table);
                    }, 0);
                },
                editurl: "{{ path('icsoc_sound_opr_del') }}",//nothing is saved 定义对form编辑时的url
                caption: "{{ 'Speech list'|trans }}" //表格名称
            });
            {{ gridNav(false,false,true,false,true,true,path('icsoc_sound_add'),path('icsoc_sound_edit')) }}
        });
        {{ sendKeyWord() }}

        function listen(sound_id)
        {
            var url = "{{ path('icsoc_sound_play') }}?sound_id="+sound_id;
            $('#sound_player').attr("src", url);
        }
        function downSound(sound_id)
        {
            var url = "{{ path('icsoc_sound_play') }}?sound_id="+sound_id;
            location.href = url;
        }

    </script>
{% endblock %}